{% extends 'admin/common/base.html' %}
{% block content %}
<div class="container">
    <div class="row">
        <a href="#" data-toggle="modal" data-target="#user-add" title="添加用户"> 添加用户</a>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>用户名</th>
                    <th>邮箱</th>
                    <th>注册时间</th>
                    <th>上次登录时间</th>
                    <th>权限</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                <tr>
                    <th scope="row">{{ loop.index }}</th>
                    <td>{{ user.username}}</td>
                    <td>{{ user.email}}</td>
                    <td>{{ user.member_since.strftime("%Y-%m-%d %H:%M:%S") }}</td>
                    <td>{{ user.last_seen.strftime("%Y-%m-%d %H:%M:%S") }}</td>
                    {% if user.is_admin() %}
                        <td>管理员</td>
                    {% elif user.is_vip() %}
                        <td>vip用户</td>
                    {% else %}
                        <td>一般用户</td>
                    {% endif %}
                    {% if user.status %}
                        <td>正常</td>
                    {% else %}
                        <td>注销</td>
                    {% endif %}
                    <td>
                        <a href="{{ url_for('admin.user_edit', user_id=user.id) }}"> 修改</a> |
                        <a href="javascript:delete_user_{{ user.id }}()">删除</a>
                        <form method="post" role="form" id="delete_user_{{ user.id }}">
                            {{ deleteUserForm.hidden_tag() }}
                            {{ deleteUserForm.user_id(hidden="",class="hidden", value=user.id) }}
                        </form>
                        <script type="text/javascript">
                           function delete_user_{{ user.id }}(){
                               if(confirm('确定要删除该用户吗?')){
                                $("#delete_user_{{ user.id }}").submit() ;
                               }
                           }
                        </script>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
<!-- Modal -->
<div class="modal fade bs-example-modal-sm" id="user-add" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="add-user">
                <form method="post" role="form">
                    {{ addUserForm.hidden_tag() }}                    
                    <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i> </span>
                        {{ addUserForm.username(class="form-control", placeholder="用户名",required="", autofocus="") }}
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i> </span>
                        {{ addUserForm.email(class="form-control", placeholder="邮 箱", required="") }}
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-briefcase"></i> </span>
                        {{ addUserForm.role(class="form-control", required="") }}
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-tree-deciduous"></i> </span>
                        {{ addUserForm.status(class="form-control", required="") }}
                    </div>
                    <div class="modal-footer">
                        <input class="btn btn-default" type="reset" value="重 置">
                        {{ addUserForm.submit(class="btn btn-primary") }}
                    </div>
                </form>
            </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}